package la.bbs558.aop.delay.handler;

import la.bbs558.aop.delay.DelayHandler;
import la.bbs558.entity.BbsClass;
import la.bbs558.entity.BbsClassActive;
import la.bbs558.service.BbsClassActiveService;
import la.bbs558.service.BbsClassService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @Classname DelayUserHandler
 * @Description TODO
 * @Date 2023/11/11 17:37
 * @Created by weihanmin
 */
@Component
@Slf4j
public abstract class BbsClassActiveDelayHandler implements DelayHandler {
    @Resource
    protected BbsClassService bbsClassService;
    @Resource
    protected BbsClassActiveService bbsClassActiveService;

    final protected BbsClassActiveContext initCtx(Long classId){
        BbsClassActiveContext activeContext = new BbsClassActiveContext();
        //查询最新的主题活动
        BbsClass bbsClass = bbsClassService.getById(classId);
        if(bbsClass == null){
            throw new RuntimeException("主题不存在");
        }
        Long activityId = bbsClass.getActivityId();
        BbsClassActive bbsClassActive = bbsClassActiveService.getById(activityId);
        if(bbsClassActive == null){
            throw new RuntimeException("主题活动不存在");
        }
        activeContext.setBbsClass(bbsClass);
        activeContext.setBbsClassActive(bbsClassActive);
        return activeContext;
    }

    @Data
    public static class BbsClassActiveContext{
        private BbsClassActive bbsClassActive;
        private BbsClass bbsClass;
    }

}
